﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class FoodCupboard : Construction, IConWork
{
    public override string Title { get; } = "食物自助机";
    public override string Explain { get; } = "懒得编了";
    public float timer;
    public List<int> resourceIds = new List<int>();

    protected override void Start()
    {
        base.Start();
        foreach (var config in ConfigurationManager.Instance.EntityResourceConfigs)
        {
            if (config.Value.isEdible)
            {
                resourceIds.Add(config.Key);
            }
        }
    }
    public ConstructionState Work()
    {
        timer += Time.deltaTime;
        if (timer > GameValue.PartRate * 2)
        {
            timer = 0;
            //生成一个食物
            if (resourceIds.Count > 0)
            {
                int index = Random.Range(0, resourceIds.Count);
                EntityManager.Instance.TryInstanceEntityResouce(transform.localPosition, out _, resourceIds[index], 1, Constants.HoldState.Hold, GameManager.Instance.fleet.gameObject);
            }
        }
        return ConstructionState.work;
    }
}
